home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / suplight.zip / WEAPONS.QC < prev   
Text File  |  1996-08-18  |  28KB  |  1,332 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav"); // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");  // super spikes
  21.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local   vector  source;
  40.     local   vector  org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     {       // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector    vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local   entity missile, mpuff;
  91.     local   vector  org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');            
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector    vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity  multi_ent;
  159. float   multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local   vector  vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local   vector direction;
  238.     local   vector  src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  273.     dir = aim (self, 100000);
  274.     FireBullets (6, dir, '0.04 0.04 0');
  275. };
  276.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()  s_explode1      =       [0,             s_explode2] {};
  312. void()  s_explode2      =       [1,             s_explode3] {};
  313. void()  s_explode3      =       [2,             s_explode4] {};
  314. void()  s_explode4      =       [3,             s_explode5] {};
  315. void()  s_explode5      =       [4,             s_explode6] {};
  316. void()  s_explode6      =       [5,             SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.     setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330.     local float     damg;
  331.  
  332.     if (other == self.owner)
  333.         return;         // don't explode on owner
  334.  
  335.     if (pointcontents(self.origin) == CONTENT_SKY)
  336.     {
  337.         remove(self);
  338.         return;
  339.     }
  340.  
  341.     damg = 100 + random()*20;
  342.     
  343.     if (other.health)
  344.     {
  345.         if (other.classname == "monster_shambler")
  346.             damg = damg * 0.5;      // mostly immune
  347.         T_Damage (other, self, self.owner, damg );
  348.     }
  349.  
  350.     // don't do radius damage to the other, because all the damage
  351.     // was done in the impact
  352.     T_RadiusDamage (self, self.owner, 120, other);
  353.  
  354. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  355.     self.origin = self.origin - 8*normalize(self.velocity);
  356.  
  357.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  358.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  359.     WriteCoord (MSG_BROADCAST, self.origin_x);
  360.     WriteCoord (MSG_BROADCAST, self.origin_y);
  361.     WriteCoord (MSG_BROADCAST, self.origin_z);
  362.  
  363.     BecomeExplosion ();
  364. };
  365.  
  366.  
  367.  
  368. /*
  369. ================
  370. W_FireRocket
  371. ================
  372. */
  373. void() W_FireRocket =
  374. {
  375.     local   entity missile, mpuff;
  376.     
  377.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  378.     
  379.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  380.  
  381.     self.punchangle_x = -2;
  382.  
  383.     missile = spawn ();
  384.     missile.owner = self;
  385.     missile.movetype = MOVETYPE_FLYMISSILE;
  386.     missile.solid = SOLID_BBOX;
  387.         
  388. // set missile speed    
  389.  
  390.     makevectors (self.v_angle);
  391.     missile.velocity = aim(self, 1000);
  392.     missile.velocity = missile.velocity * 1000;
  393.     missile.angles = vectoangles(missile.velocity);
  394.     
  395.     missile.touch = T_MissileTouch;
  396.     
  397. // set missile duration
  398.     missile.nextthink = time + 5;
  399.     missile.think = SUB_Remove;
  400.  
  401.     setmodel (missile, "progs/missile.mdl");
  402.     setsize (missile, '0 0 0', '0 0 0');            
  403.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  404. };
  405.  
  406. /*
  407. ===============================================================================
  408.  
  409. LIGHTNING
  410.  
  411. ===============================================================================
  412. */
  413.  
  414. /*
  415. =================
  416. LightningDamage
  417. =================
  418. */
  419. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  420. {
  421.     local entity            e1, e2;
  422.     local vector            f;
  423.     
  424.     f = p2 - p1;
  425.     normalize (f);
  426.     f_x = 0 - f_y;
  427.     f_y = f_x;
  428.     f_z = 0;
  429.     f = f*16;
  430.  
  431.     e1 = e2 = world;
  432.  
  433.     traceline (p1, p2, FALSE, self);
  434.     if (trace_ent.takedamage)
  435.     {
  436.         particle (trace_endpos, '0 0 100', 225, damage*4);
  437.         T_Damage (trace_ent, from, from, damage);
  438.         if (self.classname == "player")
  439.         {
  440.             if (other.classname == "player")
  441.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  442.         }
  443.     }
  444.     e1 = trace_ent;
  445.  
  446.     traceline (p1 + f, p2 + f, FALSE, self);
  447.     if (trace_ent != e1 && trace_ent.takedamage)
  448.     {
  449.         particle (trace_endpos, '0 0 100', 225, damage*4);
  450.         T_Damage (trace_ent, from, from, damage);
  451.     }
  452.     e2 = trace_ent;
  453.  
  454.     traceline (p1 - f, p2 - f, FALSE, self);
  455.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  456.     {
  457.         particle (trace_endpos, '0 0 100', 225, damage*4);
  458.         T_Damage (trace_ent, from, from, damage);
  459.     }
  460. };
  461.  
  462. entity() HomeFindTarget = 
  463. {
  464.     local entity head, selected;
  465.     local float dist,mindist;
  466.     dist = 50000;
  467.     mindist = dist;
  468.     selected = world;
  469.     head = findradius(self.origin, dist);
  470.     while(head)
  471.     {
  472.         if( (head.health > 1) && (head != self) && (head != self.owner) )
  473.         {
  474.             traceline(self.origin,head.origin,TRUE,self);
  475.             if ( (trace_fraction >= 1) && (vlen(head.origin - self.origin) < dist) )
  476.             {
  477.                 dist = vlen(head.origin - self.origin);
  478.                 if (dist < mindist)
  479.                 {
  480.                     mindist = dist;
  481.                     selected = head;
  482.                 }
  483.             }
  484.         }               
  485.         head = head.chain;
  486.     }
  487. /*        if (selected != world)
  488.     {
  489.         dprint ("Homing->");
  490.         dprint (selected.classname);
  491.         dprint ("\n");
  492.         dprint ("Distance = ");
  493.         dprint (ftos(mindist));
  494.         dprint ("\n");
  495.     }       */
  496.     return selected;
  497. };
  498.  
  499. void() W_FireLightning =
  500. {
  501.     local   vector          org;
  502.  
  503.     if (self.ammo_cells < 1)
  504.     {
  505.         self.weapon = W_BestWeapon ();
  506.         W_SetCurrentAmmo ();
  507.         return;
  508.     }
  509.  
  510. // explode if under water
  511.     if (self.waterlevel > 1)
  512.     {
  513.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  514.         self.ammo_cells = 0;
  515.         W_SetCurrentAmmo ();
  516.         return;
  517.     }
  518.  
  519.     if (self.t_width < time)
  520.     {
  521.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  522.         self.t_width = time + 0.6;
  523.     }
  524.     self.punchangle_x = -2;
  525.  
  526.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  527.  
  528.     org = self.origin + '0 0 16';
  529.     
  530.     traceline (org, org + v_forward*600, TRUE, self);
  531.  
  532.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  533.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  534.     WriteEntity (MSG_BROADCAST, self);
  535.     WriteCoord (MSG_BROADCAST, org_x);
  536.     WriteCoord (MSG_BROADCAST, org_y);
  537.     WriteCoord (MSG_BROADCAST, org_z);
  538.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  539.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  540.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  541.  
  542.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  543. };
  544.  
  545. void() W_FireLightning2 =
  546. {
  547.     local   entity  e1;
  548.     local   vector  org;
  549.  
  550.     if (self.ammo_cells < 1)
  551.     {
  552.         self.weapon = W_BestWeapon ();
  553.         W_SetCurrentAmmo ();
  554.         return;
  555.     }
  556.  
  557. // explode if under water
  558.     if (self.waterlevel > 1)
  559.     {
  560.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  561.         self.ammo_cells = 0;
  562.         W_SetCurrentAmmo ();
  563.         return;
  564.     }
  565.     e1 = world;
  566.     e1 = HomeFindTarget();
  567.     if (e1 == world)
  568.         return;
  569.     traceline(self.origin,e1.origin,TRUE,self);
  570.             
  571.     if (trace_inopen && trace_inwater)
  572.         return;
  573.     
  574.     if (self.t_width < time)
  575.     {
  576.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  577.         self.t_width = time + 0.6;
  578.     }
  579.     self.punchangle_x = -5;
  580.  
  581.     self.currentammo = self.ammo_cells = self.ammo_cells - 10;
  582.  
  583.     org = self.origin + '0 0 16';
  584.     
  585.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  586.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  587.     WriteEntity (MSG_BROADCAST, self);
  588.     WriteCoord (MSG_BROADCAST, org_x);
  589.     WriteCoord (MSG_BROADCAST, org_y);
  590.     WriteCoord (MSG_BROADCAST, org_z);
  591.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  592.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  593.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  594.  
  595.     LightningDamage (self.origin, trace_endpos , self, 60);
  596.     self.nextthink = time + 0.2;
  597.     self.think = HomeFindTarget;
  598. };
  599.  
  600.  
  601. //=============================================================================
  602.  
  603.  
  604. void() GrenadeExplode =
  605. {
  606.     T_RadiusDamage (self, self.owner, 120, world);
  607.  
  608.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  609.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  610.     WriteCoord (MSG_BROADCAST, self.origin_x);
  611.     WriteCoord (MSG_BROADCAST, self.origin_y);
  612.     WriteCoord (MSG_BROADCAST, self.origin_z);
  613.  
  614.     BecomeExplosion ();
  615. };
  616.  
  617. void() GrenadeTouch =
  618. {
  619.     if (other == self.owner)
  620.         return;         // don't explode on owner
  621.     if (other.takedamage == DAMAGE_AIM)
  622.     {
  623.         GrenadeExplode();
  624.         return;
  625.     }
  626.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  627.     if (self.velocity == '0 0 0')
  628.         self.avelocity = '0 0 0';
  629. };
  630.  
  631. /*
  632. ================
  633. W_FireGrenade
  634. ================
  635. */
  636. void() W_FireGrenade =
  637. {
  638.     local   entity missile, mpuff;
  639.     
  640.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  641.     
  642.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  643.  
  644.     self.punchangle_x = -2;
  645.  
  646.     missile = spawn ();
  647.     missile.owner = self;
  648.     missile.movetype = MOVETYPE_BOUNCE;
  649.     missile.solid = SOLID_BBOX;
  650.     missile.classname = "grenade";
  651.         
  652. // set missile speed    
  653.  
  654.     makevectors (self.v_angle);
  655.  
  656.     if (self.v_angle_x)
  657.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  658.     else
  659.     {
  660.         missile.velocity = aim(self, 10000);
  661.         missile.velocity = missile.velocity * 600;
  662.         missile.velocity_z = 200;
  663.     }
  664.  
  665.     missile.avelocity = '300 300 300';
  666.  
  667.     missile.angles = vectoangles(missile.velocity);
  668.     
  669.     missile.touch = GrenadeTouch;
  670.     
  671. // set missile duration
  672.     missile.nextthink = time + 2.5;
  673.     missile.think = GrenadeExplode;
  674.  
  675.     setmodel (missile, "progs/grenade.mdl");
  676.     setsize (missile, '0 0 0', '0 0 0');            
  677.     setorigin (missile, self.origin);
  678. };
  679.  
  680.  
  681. //=============================================================================
  682.  
  683. void() spike_touch;
  684. void() superspike_touch;
  685.  
  686.  
  687. /*
  688. ===============
  689. launch_spike
  690.  
  691. Used for both the player and the ogre
  692. ===============
  693. */
  694. void(vector org, vector dir) launch_spike =
  695. {
  696.     newmis = spawn ();
  697.     newmis.owner = self;
  698.     newmis.movetype = MOVETYPE_FLYMISSILE;
  699.     newmis.solid = SOLID_BBOX;
  700.  
  701.     newmis.angles = vectoangles(dir);
  702.     
  703.     newmis.touch = spike_touch;
  704.     newmis.classname = "spike";
  705.     newmis.think = SUB_Remove;
  706.     newmis.nextthink = time + 6;
  707.     setmodel (newmis, "progs/spike.mdl");
  708.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  709.     setorigin (newmis, org);
  710.  
  711.     newmis.velocity = dir * 1000;
  712. };
  713.  
  714. void() W_FireSuperSpikes =
  715. {
  716.     local vector    dir;
  717.     local entity    old;
  718.     
  719.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  720.     self.attack_finished = time + 0.2;
  721.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  722.     dir = aim (self, 1000);
  723.     launch_spike (self.origin + '0 0 16', dir);
  724.     newmis.touch = superspike_touch;
  725.     setmodel (newmis, "progs/s_spike.mdl");
  726.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  727.     self.punchangle_x = -2;
  728. };
  729.  
  730. void(float ox) W_FireSpikes =
  731. {
  732.     local vector    dir;
  733.     local entity    old;
  734.     
  735.     makevectors (self.v_angle);
  736.     
  737.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  738.     {
  739.         W_FireSuperSpikes ();
  740.         return;
  741.     }
  742.  
  743.     if (self.ammo_nails < 1)
  744.     {
  745.         self.weapon = W_BestWeapon ();
  746.         W_SetCurrentAmmo ();
  747.         return;
  748.     }
  749.  
  750.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  751.     self.attack_finished = time + 0.2;
  752.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  753.     dir = aim (self, 1000);
  754.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  755.  
  756.     self.punchangle_x = -2;
  757. };
  758.  
  759.  
  760.  
  761. .float hit_z;
  762. void() spike_touch =
  763. {
  764. local float rand;
  765.     if (other == self.owner)
  766.         return;
  767.  
  768.     if (other.solid == SOLID_TRIGGER)
  769.         return; // trigger field, do nothing
  770.  
  771.     if (pointcontents(self.origin) == CONTENT_SKY)
  772.     {
  773.         remove(self);
  774.         return;
  775.     }
  776.     
  777. // hit something that bleeds
  778.     if (other.takedamage)
  779.     {
  780.         spawn_touchblood (9);
  781.         T_Damage (other, self, self.owner, 9);
  782.     }
  783.     else
  784.     {
  785.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  786.         
  787.         if (self.classname == "wizspike")
  788.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  789.         else if (self.classname == "knightspike")
  790.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  791.         else
  792.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  793.         WriteCoord (MSG_BROADCAST, self.origin_x);
  794.         WriteCoord (MSG_BROADCAST, self.origin_y);
  795.         WriteCoord (MSG_BROADCAST, self.origin_z);
  796.     }
  797.  
  798.     remove(self);
  799.  
  800. };
  801.  
  802. void() superspike_touch =
  803. {
  804. local float rand;
  805.     if (other == self.owner)
  806.         return;
  807.  
  808.     if (other.solid == SOLID_TRIGGER)
  809.         return; // trigger field, do nothing
  810.  
  811.     if (pointcontents(self.origin) == CONTENT_SKY)
  812.     {
  813.         remove(self);
  814.         return;
  815.     }
  816.     
  817. // hit something that bleeds
  818.     if (other.takedamage)
  819.     {
  820.         spawn_touchblood (18);
  821.         T_Damage (other, self, self.owner, 18);
  822.     }
  823.     else
  824.     {
  825.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  826.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  827.         WriteCoord (MSG_BROADCAST, self.origin_x);
  828.         WriteCoord (MSG_BROADCAST, self.origin_y);
  829.         WriteCoord (MSG_BROADCAST, self.origin_z);
  830.     }
  831.  
  832.     remove(self);
  833.  
  834. };
  835.  
  836.  
  837. /*
  838. ===============================================================================
  839.  
  840. PLAYER WEAPON USE
  841.  
  842. ===============================================================================
  843. */
  844.  
  845. void() W_SetCurrentAmmo =
  846. {
  847.     player_run ();          // get out of any weapon firing states
  848.  
  849.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  850.     
  851.     if (self.weapon == IT_AXE)
  852.     {
  853.         self.currentammo = 0;
  854.         self.weaponmodel = "progs/v_axe.mdl";
  855.         self.weaponframe = 0;
  856.     }
  857.     else if (self.weapon == IT_SHOTGUN)
  858.     {
  859.         self.currentammo = self.ammo_shells;
  860.         self.weaponmodel = "progs/v_shot.mdl";
  861.         self.weaponframe = 0;
  862.         self.items = self.items | IT_SHELLS;
  863.     }
  864.     else if (self.weapon == IT_SUPER_SHOTGUN)
  865.     {
  866.         self.currentammo = self.ammo_shells;
  867.         self.weaponmodel = "progs/v_shot2.mdl";
  868.         self.weaponframe = 0;
  869.         self.items = self.items | IT_SHELLS;
  870.     }
  871.     else if (self.weapon == IT_NAILGUN)
  872.     {
  873.         self.currentammo = self.ammo_nails;
  874.         self.weaponmodel = "progs/v_nail.mdl";
  875.         self.weaponframe = 0;
  876.         self.items = self.items | IT_NAILS;
  877.     }
  878.     else if (self.weapon == IT_SUPER_NAILGUN)
  879.     {
  880.         self.currentammo = self.ammo_nails;
  881.         self.weaponmodel = "progs/v_nail2.mdl";
  882.         self.weaponframe = 0;
  883.         self.items = self.items | IT_NAILS;
  884.     }
  885.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  886.     {
  887.         self.currentammo = self.ammo_rockets;
  888.         self.weaponmodel = "progs/v_rock.mdl";
  889.         self.weaponframe = 0;
  890.         self.items = self.items | IT_ROCKETS;
  891.     }
  892.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  893.     {
  894.         self.currentammo = self.ammo_rockets;
  895.         self.weaponmodel = "progs/v_rock2.mdl";
  896.         self.weaponframe = 0;
  897.         self.items = self.items | IT_ROCKETS;
  898.     }
  899.     else if ((self.weapon == IT_LIGHTNING) || (self.weapon == IT_SUPER_LIGHTNING))
  900.     {
  901.         self.currentammo = self.ammo_cells;
  902.         self.weaponmodel = "progs/v_light.mdl";
  903.         self.weaponframe = 0;
  904.         self.items = self.items | IT_CELLS;
  905.     }
  906.     else
  907.     {
  908.         self.currentammo = 0;
  909.         self.weaponmodel = "";
  910.         self.weaponframe = 0;
  911.     }
  912. };
  913.  
  914. float() W_BestWeapon =
  915. {
  916.     local   float   it;
  917.     
  918.     it = self.items;
  919.  
  920.     if(self.ammo_cells >= 10 && (it & IT_SUPER_LIGHTNING) )
  921.         return IT_SUPER_LIGHTNING;
  922.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  923.         return IT_LIGHTNING;
  924.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  925.         return IT_SUPER_NAILGUN;
  926.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  927.         return IT_SUPER_SHOTGUN;
  928.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  929.         return IT_NAILGUN;
  930.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  931.         return IT_SHOTGUN;
  932.         
  933. /*
  934.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  935.         return IT_ROCKET_LAUNCHER;
  936.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  937.         return IT_GRENADE_LAUNCHER;
  938.  
  939. */
  940.  
  941.     return IT_AXE;
  942. };
  943.  
  944. float() W_CheckNoAmmo =
  945. {
  946.     if (self.currentammo > 0)
  947.         return TRUE;
  948.  
  949.     if (self.weapon == IT_AXE)
  950.         return TRUE;
  951.     
  952.     self.weapon = W_BestWeapon ();
  953.  
  954.     W_SetCurrentAmmo ();
  955.     
  956. // drop the weapon down
  957.     return FALSE;
  958. };
  959.  
  960. /*
  961. ============
  962. W_Attack
  963.  
  964. An attack impulse can be triggered now
  965. ============
  966. */
  967. void()  player_axe1;
  968. void()  player_axeb1;
  969. void()  player_axec1;
  970. void()  player_axed1;
  971. void()  player_shot1;
  972. void()  player_nail1;
  973. void()  player_light1;
  974. void()  player_rocket1;
  975.  
  976. void() W_Attack =
  977. {
  978.     local   float   r;
  979.  
  980.     if (!W_CheckNoAmmo ())
  981.         return;
  982.  
  983.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  984.     self.show_hostile = time + 1;   // wake monsters up
  985.  
  986.     if (self.weapon == IT_AXE)
  987.     {
  988.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  989.         r = random();
  990.         if (r < 0.25)
  991.             player_axe1 ();
  992.         else if (r<0.5)
  993.             player_axeb1 ();
  994.         else if (r<0.75)
  995.             player_axec1 ();
  996.         else
  997.             player_axed1 ();
  998.         self.attack_finished = time + 0.5;
  999.     }
  1000.     else if (self.weapon == IT_SHOTGUN)
  1001.     {
  1002.         player_shot1 ();
  1003.         W_FireShotgun ();
  1004.         self.attack_finished = time + 0.5;
  1005.     }
  1006.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1007.     {
  1008.         player_shot1 ();
  1009.         W_FireSuperShotgun ();
  1010.         self.attack_finished = time + 0.7;
  1011.     }
  1012.     else if (self.weapon == IT_NAILGUN)
  1013.     {
  1014.         player_nail1 ();
  1015.     }
  1016.     else if (self.weapon == IT_SUPER_NAILGUN)
  1017.     {
  1018.         player_nail1 ();
  1019.     }
  1020.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1021.     {
  1022.         player_rocket1();
  1023.         W_FireGrenade();
  1024.         self.attack_finished = time + 0.6;
  1025.     }
  1026.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1027.     {
  1028.         player_rocket1();
  1029.         W_FireRocket();
  1030.         self.attack_finished = time + 0.8;
  1031.     }
  1032.     else if ((self.weapon == IT_LIGHTNING) || (self.weapon == IT_SUPER_LIGHTNING))
  1033.     {
  1034.         player_light1();
  1035.         self.attack_finished = time + 0.1;
  1036.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1037.     }
  1038. };
  1039.  
  1040. /*
  1041. ============
  1042. W_ChangeWeapon
  1043.  
  1044. ============
  1045. */
  1046. void() W_ChangeWeapon =
  1047. {
  1048.     local   float   it, am, fl;
  1049.     
  1050.     it = self.items;
  1051.     am = 0;
  1052.     
  1053.     if (self.impulse == 1)
  1054.     {
  1055.         fl = IT_AXE;
  1056.     }
  1057.     else if (self.impulse == 2)
  1058.     {
  1059.         fl = IT_SHOTGUN;
  1060.         if (self.ammo_shells < 1)
  1061.             am = 1;
  1062.     }
  1063.     else if (self.impulse == 3)
  1064.     {
  1065.         fl = IT_SUPER_SHOTGUN;
  1066.         if (self.ammo_shells < 2)
  1067.             am = 1;
  1068.     }               
  1069.     else if (self.impulse == 4)
  1070.     {
  1071.         fl = IT_NAILGUN;
  1072.         if (self.ammo_nails < 1)
  1073.             am = 1;
  1074.     }
  1075.     else if (self.impulse == 5)
  1076.     {
  1077.         fl = IT_SUPER_NAILGUN;
  1078.         if (self.ammo_nails < 2)
  1079.             am = 1;
  1080.     }
  1081.     else if (self.impulse == 6)
  1082.     {
  1083.         fl = IT_GRENADE_LAUNCHER;
  1084.         if (self.ammo_rockets < 1)
  1085.             am = 1;
  1086.     }
  1087.     else if (self.impulse == 7)
  1088.     {
  1089.         fl = IT_ROCKET_LAUNCHER;
  1090.         if (self.ammo_rockets < 1)
  1091.             am = 1;
  1092.     }
  1093.     else if (self.impulse == 8)
  1094.     {
  1095.         if (self.weapon == IT_LIGHTNING) 
  1096.         if (self.ammo_cells >= 10)
  1097.         {
  1098.             self.weapon = IT_SUPER_LIGHTNING;
  1099.             sprint(self,"Super Lightning gun mode\n");
  1100.             return;
  1101.         }  
  1102.         else
  1103.             sprint(self,"Not enough cells for Super Lightning gun\n");
  1104.         
  1105.         fl = IT_LIGHTNING;
  1106.         if (self.ammo_cells < 1)
  1107.             am = 1;
  1108.         else
  1109.             sprint(self,"Lightning gun mode\n");
  1110.  
  1111.     }
  1112.  
  1113.     self.impulse = 0;
  1114.     
  1115.     if (!(self.items & fl))
  1116.     {       // don't have the weapon or the ammo
  1117.         sprint (self, "no weapon.\n");
  1118.         return;
  1119.     }
  1120.     
  1121.     if (am)
  1122.     {       // don't have the ammo
  1123.         sprint (self, "not enough ammo.\n");
  1124.         return;
  1125.     }
  1126.  
  1127. //
  1128. // set weapon, set ammo
  1129. //
  1130.     self.weapon = fl;               
  1131.     W_SetCurrentAmmo ();
  1132. };
  1133.  
  1134. /*
  1135. ============
  1136. CheatCommand
  1137. ============
  1138. */
  1139. void() CheatCommand =
  1140. {
  1141.     if (deathmatch || coop)
  1142.         return;
  1143.  
  1144.     self.ammo_rockets = 100;
  1145.     self.ammo_nails = 200;
  1146.     self.ammo_shells = 100;
  1147.     self.items = self.items | 
  1148.         IT_AXE |
  1149.         IT_SHOTGUN |
  1150.         IT_SUPER_SHOTGUN |
  1151.         IT_NAILGUN |
  1152.         IT_SUPER_NAILGUN |
  1153.         IT_GRENADE_LAUNCHER |
  1154.         IT_ROCKET_LAUNCHER |
  1155.         IT_KEY1 | IT_KEY2;
  1156.  
  1157.     self.ammo_cells = 200;
  1158.     self.items = self.items | IT_LIGHTNING | IT_SUPER_LIGHTNING;
  1159.  
  1160.     self.weapon = IT_ROCKET_LAUNCHER;
  1161.     self.impulse = 0;
  1162.     W_SetCurrentAmmo ();
  1163. };
  1164.  
  1165. /*
  1166. ============
  1167. CycleWeaponCommand
  1168.  
  1169. Go to the next weapon with ammo
  1170. ============
  1171. */
  1172. void() CycleWeaponCommand =
  1173. {
  1174.     local   float   it, am;
  1175.     
  1176.     it = self.items;
  1177.     self.impulse = 0;
  1178.     
  1179.     while (1)
  1180.     {
  1181.         am = 0;
  1182.  
  1183.         if (self.weapon == IT_SUPER_LIGHTNING)
  1184.         {
  1185.             self.weapon = IT_AXE;
  1186.         }
  1187.         else if (self.weapon == IT_AXE)
  1188.         {
  1189.             self.weapon = IT_SHOTGUN;
  1190.             if (self.ammo_shells < 1)
  1191.                 am = 1;
  1192.         }
  1193.         else if (self.weapon == IT_SHOTGUN)
  1194.         {
  1195.             self.weapon = IT_SUPER_SHOTGUN;
  1196.             if (self.ammo_shells < 2)
  1197.                 am = 1;
  1198.         }               
  1199.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1200.         {
  1201.             self.weapon = IT_NAILGUN;
  1202.             if (self.ammo_nails < 1)
  1203.                 am = 1;
  1204.         }
  1205.         else if (self.weapon == IT_NAILGUN)
  1206.         {
  1207.             self.weapon = IT_SUPER_NAILGUN;
  1208.             if (self.ammo_nails < 2)
  1209.                 am = 1;
  1210.         }
  1211.         else if (self.weapon == IT_SUPER_NAILGUN)
  1212.         {
  1213.             self.weapon = IT_GRENADE_LAUNCHER;
  1214.             if (self.ammo_rockets < 1)
  1215.                 am = 1;
  1216.         }
  1217.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1218.         {
  1219.             self.weapon = IT_ROCKET_LAUNCHER;
  1220.             if (self.ammo_rockets < 1)
  1221.                 am = 1;
  1222.         }
  1223.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1224.         {
  1225.             self.weapon = IT_LIGHTNING;
  1226.             if (self.ammo_cells < 1)
  1227.                 am = 1;
  1228.         }
  1229.         else if (self.weapon == IT_LIGHTNING)
  1230.         {
  1231.             self.weapon = IT_SUPER_LIGHTNING;
  1232.         }
  1233.     
  1234.         if ( (self.items & self.weapon) && am == 0)
  1235.         {
  1236.             W_SetCurrentAmmo ();
  1237.             return;
  1238.         }
  1239.     }
  1240.  
  1241. };
  1242.  
  1243. /*
  1244. ============
  1245. ServerflagsCommand
  1246.  
  1247. Just for development
  1248. ============
  1249. */
  1250. void() ServerflagsCommand =
  1251. {
  1252.     serverflags = serverflags * 2 + 1;
  1253. };
  1254.  
  1255. void() QuadCheat =
  1256. {
  1257.     if (deathmatch || coop)
  1258.         return;
  1259.     self.super_time = 1;
  1260.     self.super_damage_finished = time + 30;
  1261.     self.items = self.items | IT_QUAD;
  1262.     dprint ("quad cheat\n");
  1263. };
  1264.  
  1265. /*
  1266. ============
  1267. ImpulseCommands
  1268.  
  1269. ============
  1270. */
  1271. void() ImpulseCommands =
  1272. {
  1273.     if (self.impulse >= 1 && self.impulse <= 8)
  1274.         W_ChangeWeapon ();
  1275.  
  1276.     if (self.impulse == 9)
  1277.         CheatCommand ();
  1278.     if (self.impulse == 10)
  1279.         CycleWeaponCommand ();
  1280.     if (self.impulse == 11)
  1281.         ServerflagsCommand ();
  1282.     
  1283.     if (self.impulse == 255)
  1284.         QuadCheat ();
  1285.         
  1286.     self.impulse = 0;
  1287. };
  1288.  
  1289. /*
  1290. ============
  1291. W_WeaponFrame
  1292.  
  1293. Called every frame so impulse events can be handled as well as possible
  1294. ============
  1295. */
  1296. void() W_WeaponFrame =
  1297. {
  1298.     if (time < self.attack_finished)
  1299.         return;
  1300.  
  1301.     ImpulseCommands ();
  1302.     
  1303. // check for attack
  1304.     if (self.button0)
  1305.     {
  1306.         SuperDamageSound ();
  1307.         W_Attack ();
  1308.     }
  1309. };
  1310.  
  1311. /*
  1312. ========
  1313. SuperDamageSound
  1314.  
  1315. Plays sound if needed
  1316. ========
  1317. */
  1318. void() SuperDamageSound =
  1319. {
  1320.     if (self.super_damage_finished > time)
  1321.     {
  1322.         if (self.super_sound < time)
  1323.         {
  1324.             self.super_sound = time + 1;
  1325.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1326.         }
  1327.     }
  1328.     return;
  1329. };
  1330.  
  1331.  
  1332.